home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / BTREE_C.ZIP / EMAILNME.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-05  |  2.8 KB  |  128 lines

  1. /**************************************
  2.  ** EMAILNME.CPP - by John Adkins    **
  3.  **                06/05/92          **
  4.  **                                  **
  5.  ** Email Name Class                 **
  6.  **************************************/
  7.  
  8. /**************************************
  9.  ******  INCLUDES  ********************
  10.  **************************************/
  11.  
  12. #include "emailnme.h"
  13.  
  14. /**************************************
  15.  ******  METHODS  *********************
  16.  **************************************/
  17.  
  18. TEmailName::TEmailName(const char *str)
  19. {
  20.   char          *semi, *colon, *frst;
  21.   char          *temp;
  22.  
  23.   firstname=0;
  24.   lastname=0;
  25.   userid=0;
  26.   servername=0;
  27.   temp=strdup(str);
  28.   colon=strrchr(temp,':');
  29.   if(colon)
  30.   {
  31.     userid=strdup(colon+1);
  32.     *colon=0;
  33.     semi=strrchr(temp,';');
  34.     if(semi)
  35.     {
  36.       servername=strdup(semi+1);
  37.       *semi=0;
  38.       frst=strchr(temp,' ');
  39.       if(frst)
  40.       {
  41.         firstname=strdup(frst+1);
  42.         *frst=0;
  43.       }
  44.       lastname=strdup(temp);
  45.     }
  46.   }
  47.   free(temp);
  48. }
  49.  
  50. TEmailName::TEmailName(TEmailName &source)
  51. {
  52.   lastname=strdup(source.lastname);
  53.   firstname=strdup(source.firstname);
  54.   userid=strdup(source.userid);
  55.   servername=strdup(source.servername);
  56. }
  57.  
  58. TEmailName::~TEmailName()
  59. {
  60.   if(firstname) free(firstname);
  61.   if(lastname) free(lastname);
  62.   if(userid) free(userid);
  63.   if(servername) free(servername);
  64. }
  65.  
  66. int TEmailName::isEqual(const Object &compare) const
  67. {
  68.   int           equal=0;
  69.  
  70.   if(compare.isA()==isA())
  71.   {
  72.     TEmailName     &en=(TEmailName &)compare;
  73.  
  74.     if(stricmp(userid,en.userid)==0)
  75.       equal=1;
  76.     if(stricmp(lastname,en.lastname)==0)
  77.     {
  78.       for(int i=0, count=0; i<strlen(userid) && i<strlen(en.userid); i++)
  79.       {
  80.         if(userid[i]==en.userid[i])
  81.           count++;
  82.       }
  83.       if(count>strlen(userid)/2 && count>strlen(en.userid)/2)
  84.         equal=1;
  85.     }
  86.   }
  87.   return(equal);
  88. }
  89.  
  90. int TEmailName::isLessThan(const Object &compare) const
  91. {
  92.   if(compare.isA()==isA())
  93.   {
  94.     TEmailName     &en=(TEmailName &)compare;
  95.  
  96.     if(stricmp(lastname,en.lastname)<0)
  97.       return(1);
  98.     if(stricmp(lastname,en.lastname)==0)
  99.     {
  100.       if(stricmp(firstname,en.firstname)<0)
  101.         return(1);
  102.       if(stricmp(firstname,en.firstname)==0)
  103.       {
  104.         if(stricmp(servername,en.servername)<0)
  105.           return(1);
  106.         if(stricmp(servername,en.servername)==0)
  107.         {
  108.           if(stricmp(userid,en.userid)<0)
  109.             return(1);
  110.           else
  111.             return(0);
  112.         }
  113.       }
  114.     }
  115.   }
  116.   return(0);
  117. }
  118.  
  119. void TEmailName::printOn(ostream &os) const
  120. {
  121.   os << lastname << " " << firstname << ";" << servername << ":" << userid;
  122. }
  123.  
  124. /**************************************
  125.  ******  END OF EMAILNME.CPP  *********
  126.  **************************************/
  127.  
  128.